package com.atguigu.factory.absfactory.order;

import com.atguigu.factory.absfactory.pizza.Pizza;
import sun.security.pkcs11.wrapper.CK_SSL3_KEY_MAT_OUT;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 09 月 10 日 上午10:47
 */
public class OrderPizza {
    AbsFactory absFactory;

    public OrderPizza(AbsFactory absFactory) {
        this.setAbsFactory(absFactory);
    }


    private void setAbsFactory(AbsFactory absFactory) {
        this.absFactory = absFactory;
        Pizza pizza = null;
        String orderType;
        do {
            System.out.println("请输入pizza的种类:");
            orderType = getType();
            pizza = absFactory.createFactory(orderType);
            if(pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        } while (true);
    }

    private String getType() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            return bufferedReader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
